package com.ruoyi.prodata.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.prodata.service.ITotalProgressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 项目总进度
 *
 * @author zhangzhihao
 */
@RestController
@RequestMapping("/prodata/totalProgress")
public class TotalProgressController extends BaseController {

    @Autowired
    private ITotalProgressService totalProgressService;

    /**
     * 查询项目总进度
     */
    @PreAuthorize("@ss.hasPermi('prodata:statistics:list')")
    @GetMapping("/list")
    public AjaxResult list(Long projectId) {
        List<Map<String, Object>> list = totalProgressService.selectTotalProgress(projectId);

        ArrayList<String> nameList = new ArrayList<>();
        ArrayList<Long> percentList = new ArrayList<>();

        //容器转换
        list.forEach(m -> {
            nameList.add(Convert.toStr(m.get("name")));
            percentList.add(Convert.toLong(m.get("percent")));
        });

        Map<String, Object> map = new HashMap<>();
        map.put("nameList", nameList);
        map.put("percentList", percentList);

        return success(map);
    }


}
